package com.ruoyi.web.controller.his;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.his.domain.HisManufactor;
import com.ruoyi.his.service.IHisManufactorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author shebin
 * @site www.694840063@qq.com
 * @company 扬州绘鑫勤商贸有限公司
 * @create 2021-08-23 20:50
 */

@RestController
@RequestMapping("/his/manufactor")
public class hisManufactorController extends BaseController {

    @Autowired
    private IHisManufactorService hisManufactorService;

    /**
     * 获取生产厂家列表
     * @param manufactor
     * @return
     */
    @PreAuthorize("@ss.hasPermi('his:manufactor:list')")
    @GetMapping("/list")
    public TableDataInfo list(HisManufactor manufactor){
        startPage();
        List<HisManufactor> list = hisManufactorService.selectManufactorList(manufactor);
        return getDataTable(list);
    }

    /**
     * 根据编号获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('his:manufactor:query')")
    @GetMapping(value = "/{manufactorId}")
    public AjaxResult getInfo(@PathVariable Long manufactorId)
    {
        return AjaxResult.success(hisManufactorService.selectManufactorById(manufactorId));
    }

    /**
     * 新增生产厂家
     */
    @PreAuthorize("@ss.hasPermi('his:manufactor:add')")
    @Log(title = "生产厂家管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody HisManufactor manufactor)
    {
        manufactor.setCreateBy(getUsername());
        return toAjax(hisManufactorService.insertManufactor(manufactor));
    }

    /**
     * 修改生产厂家
     */
    @PreAuthorize("@ss.hasPermi('his:manufactor:edit')")
    @Log(title = "生产厂家管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody HisManufactor manufactor)
    {
        manufactor.setUpdateBy(getUsername());
        return toAjax(hisManufactorService.updateManufactor(manufactor));
    }

    /**
     * 删除生产厂家
     */
    @PreAuthorize("@ss.hasPermi('his:manufactor:remove')")
    @Log(title = "生产厂家管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{manufactorIds}")
    public AjaxResult remove(@PathVariable Long[] manufactorIds){
        return toAjax(hisManufactorService.deleteManufactorByIds(manufactorIds));
    }

    @Log(title = "生产厂家管理", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('his:manufactor:export')")
    @GetMapping("/export")
    public AjaxResult export(HisManufactor manufactor)
    {
        List<HisManufactor> list = hisManufactorService.selectManufactorList(manufactor);
        ExcelUtil<HisManufactor> util = new ExcelUtil(HisManufactor.class);
        return util.exportExcel(list, "生产厂家数据");
    }
}
